package com.the_ring.chapter07.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.SimpleOnPageChangeListener;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.the_ring.chapter07.BillPagerActivity;
import com.the_ring.chapter07.fragment.MonthFragment;

import java.util.ArrayList;
import java.util.List;

public class BillPagerAdapter extends FragmentPagerAdapter {

    private Context mContext;
    private int year;
    private List<MonthFragment> fragmentList;

    public BillPagerAdapter(@NonNull FragmentManager fm, int year) {
        super(fm);
        this.year = year;
    }

    // public BillPagerAdapter(Context context, int year) {
    //     mContext = context;
    //     this.year = year;
    //
    //     fragmentList = new ArrayList<>();
    //     for (int i = 1; i <= 12; i++) {
    //         MonthFragment monthFragment = MonthFragment.newInstance(i, year);
    //         fragmentList.add(monthFragment);
    //     }
    // }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return MonthFragment.newInstance(position + 1, year);
    }

    @Override
    public int getCount() {
        return 12;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return (position + 1) + "月份";
    }

    public void setYear(int year) {
        this.year = year;
    }
}
